package com.lifesting.ganttviewer.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class GWorkingItem implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 8352065444030374026L;
	public static final String ADD_ITEM = "ADD_ITEM";
	public static final String REMOVE_ITEM = "REMOVE_ITEM";
	
	protected transient PropertyChangeSupport propertySupport = new PropertyChangeSupport(this);
	protected int id;
	
	protected String name;
	protected Date start;
	protected Date finish;
	protected GDuration duration;
	protected GWorkingItem group;
	protected List<GWorkingItem> contains;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Date getStart() {
		return start;
	}
	public void setStart(Date start) {
		this.start = start;
	}
	public Date getFinish() {
		return finish;
	}
	public void setFinish(Date finish) {
		this.finish = finish;
	}
	public GDuration getDuration() {
		return duration;
	}
	public void setDuration(GDuration duration) {
		this.duration = duration;
	}
	public GWorkingItem getGroup() {
		return group;
	}
	public void setGroup(GWorkingItem group) {
		this.group = group;
	}
	public List<GWorkingItem> getContains() {
		return contains;
	}
	public void addSubItem(GWorkingItem item){
		if (contains == null)
			contains = new ArrayList<GWorkingItem>();
		this.contains.add(item);
		item.setGroup(this);
		propertySupport.firePropertyChange(ADD_ITEM,null,item);
	}
	public void removeSubItem(GWorkingItem item){
		this.contains.remove(item);
		item.setGroup(null);
		propertySupport.firePropertyChange(REMOVE_ITEM, item, null);
	}
	public void addProeprtyChangeListener(PropertyChangeListener listener){
		propertySupport.addPropertyChangeListener(listener);
	}
	public void removePropertyChangeListener(PropertyChangeListener listener){
		propertySupport.removePropertyChangeListener(listener);
	}
	private void readObject(ObjectInputStream in) 
	throws IOException, ClassNotFoundException {
		in.defaultReadObject();
		propertySupport = new PropertyChangeSupport(this);
	}
	
}
